package com.asiainfo.dao;
/*
 * 
 * 课程数据库操作类
 */
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import com.asiainfo.bean.Course;
import com.asiainfo.database.JdbcTemplete;
import com.asiainfo.database.ResultSetHandler;

public class Course_Dao {
	//添加课程
	public int addcourse(Course course){
		JdbcTemplete jt = new JdbcTemplete();
		String sql = "insert into course(course_name,course_date) values (?,?)";
		return jt.update(sql, course.getCourse_name(),(int)new Date().getTime());
	}
	//根据课程名查找课程
	public Course findcourseByName(String coachname){
		JdbcTemplete jt = new JdbcTemplete();
		String sql = "select course_name,course_date,course_id from course where course_name=?";
		Course course = (Course) jt.quary(sql, new ResultSetHandler() {
			public Object doHandler(ResultSet rs) throws SQLException {
				Course course = null;
				if (rs.next()) {
					course = new Course();
					course.setCourse_name(rs.getString(1));
					course.setCourse_date(rs.getInt(2));
					course.setCourse_id(rs.getInt(3));
				}
				return course;
			}
		}, coachname);
		return course;
	}
	//根据课程ID查找课程
	public Course findcourseById(int id){
		JdbcTemplete jt = new JdbcTemplete();
		String sql = "select course_name,course_date,course_id from course where course_id=?";
		Course course = (Course) jt.quary(sql, new ResultSetHandler() {
			public Object doHandler(ResultSet rs) throws SQLException {
				Course course = null;
				if (rs.next()) {
					course = new Course();
					course.setCourse_name(rs.getString(1));
					course.setCourse_date(rs.getInt(2));
					course.setCourse_id(rs.getInt(3));
				}
				return course;
			}
		}, id);
		return course;
	}
}
